package uicgas.pump.commands;

import uicgas.communication.Communication;
import uicgas.globaldata.ControlMessage;
import uicgas.globaldata.MessagePayload;
import uicgas.globaldata.Messages;
import uicgas.globaldata.SelfAnnouncement;
import uicgas.globaldata.Transaction;
import uicgas.pump.PumpLogic;

/**
 * Announce the current transaction in this client
 * 
 * @author Hong Wang
 *
 */
public class AnnounceTransaction extends AbstractRemoteCommand
{
	private SelfAnnouncement announcementOfRegister = null;

	public AnnounceTransaction(PumpLogic pumpLogic,
			Communication communication, MessagePayload payload)
	{
		super(pumpLogic, communication);
		this.announcementOfRegister = (SelfAnnouncement) payload;
	}

	@Override
	public void executeRemoteCommand()
	{
		Transaction transaction = pumpLogic.getCurrentTransaction();
		transaction.setDestinationID(announcementOfRegister.getID());

		communication.sendData(new ControlMessage(Messages.TRANSACTIONREPLY,
				transaction));
	}

}
